package com.czxy.blogs.manage.web.controller;

import com.czxy.blogs.domain.Friendlink;
import com.czxy.blogs.manage.service.FriendLinkService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/friendLink")
public class FriendLinkController {

    @Autowired
    private FriendLinkService friendLinkService;


    @RequestMapping("/findAllFriendLink")
    public String findAllFriendlink(Model model,String pageNum){
        Integer thisPageNum = 1;
        if (pageNum != null && !"".equals(pageNum)){
            thisPageNum = Integer.parseInt(pageNum);
        }
        Integer pageSize = 2;
        PageInfo<Friendlink> pageInfo = friendLinkService.findAllFriendLink(thisPageNum,pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "flink";

    }

    @RequestMapping("/deleteFlink")
    public String deleteFlink(String [] fids){
        friendLinkService.deleteFLinks(fids);
        return "forward:/friendLink/findAllFriendLink.action";
    }

    @RequestMapping("/showFlink")
    public String showFlink(@RequestParam("fid") String fid, Model model){
        Friendlink friendlink = friendLinkService.view(fid);
        model.addAttribute("friendlink",friendlink);
        return "update-flink";
    }

    @RequestMapping("/updateFlink")
    public String updateFlink(Friendlink friendlink){
        friendLinkService.updateFlink(friendlink);
        return "forward:/friendLink/findAllFriendLink.action";
    }

    @RequestMapping("/addFlink")
    public String addFlink(Friendlink friendlink){
        friendLinkService.addFlink(friendlink);
        return "forward:/friendLink/findAllFriendLink.action";
    }
}
